<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <meta name="renderer" content="webkit">
    <title></title>
    <link rel="stylesheet" href="/css/pintuer.css">
    <link rel="stylesheet" href="/css/admin.css">
    <script src="/js/jquery.js"></script>
    <script src="/js/pintuer.js"></script>
    <script src="/js/vuejs-2.5.16.js"></script>
    <script src="/js/axios-0.18.0.js"></script>
	<!-- 引入样式 -->
    <link rel="stylesheet" href="/element-ui/lib/theme-chalk/index.css">
    <!-- 引入组件库 -->
    <script src="/element-ui/lib/index.js"></script>


</head>
<body>
<div class="panel admin-panel" id="moviesListDiv">
    <div class="panel-head"><strong class="icon-reorder"> 影视列表</strong> <a href="" style="float:right; display:none;">添加字段</a>
    </div>
    <div class="padding border-bottom">
        <form>
            <ul class="search" style="padding-left:10px;">
                <li><a class="button border-main icon-plus-square-o" href="/movies_add.html"> 添加影视</a></li>
                <li>搜索：</li>
                <li>
                    <select name="cid" class="input" style="width:200px; line-height:17px;" v-model="cid">
                        <option value="">请选择分类</option>
                        <option value="0">特色的</option>
                        <option value="1">高观看率</option>
                        <option value="2">高评分</option>
                        <option value="3">最新上映</option>
                    </select>
                </li>
                <li>
                    <input type="text" placeholder="请输入搜索关键字" name="keyword" class="input" v-model="keyword"
                           style="width:250px; line-height:17px;display:inline-block"/>
                    <a class="button border-main icon-search" @click="findList()"> 搜索</a></li>
            </ul>
        </form>
    </div>
    <table class="table table-hover text-center">
        <tr>
            <th width="5%">选择</th>
            <th width="5%">排序</th>
            <th>图片</th>
            <th width="10%">导演</th>
            <th>影视名称</th>
            <th>分类名称</th>
            <th width="10%">上映时间</th>
            <th width="310">操作</th>
        </tr>
        <!--循环遍历数据-->
        <tr v-for="movies in moviesList">
            <td style="text-align:left; padding-left:10px;">
                <!--
                    :value="movies.id" 原来的值
                    v-model="moviesIds" 当勾选以后 将传递的值
                -->
                <input type="checkbox" name="ids" v-model="moviesIds" :value="movies.id"/>
            </td>
            <td style="text-align:left; padding-left:20px;">{{index++}}</td>
            <td width="10%"><img :src="movies.picPath" alt="" width="70" height="50"/></td>
            <td>{{movies.director}}</td>
            <td>{{movies.title}}</td>
            <td v-if="movies.cid==0">特色的</td>
            <td v-if="movies.cid==1">高观看率</td>
            <td v-if="movies.cid==2">高评分率</td>
            <td v-if="movies.cid==3">最新上映</td>
            <td>
                {{movies.showTime}}
            </td>
            <td>
                <div class="button-group">
                    <a class="button border-main" :href="'/movies_add.html?id='+movies.id"><span class="icon-edit"></span>修改</a>
                    <a class="button border-red" href="javascript:void(0)" @click="deleteById(movies.id)">
                        <span class="icon-trash-o"></span> 删除</a>
                </div>
            </td>
        </tr>



        <tr>
            <td colspan="7" style="text-align:left;padding-left:20px;">
                <a href="javascript:void(0)" class="button border-red icon-trash-o" style="padding:5px 15px;" @click="deleteByIds()"> 批量删除</a>
				<span>总记录数：20</span>
            </td>
        </tr>
        <tr>
            <td colspan="8">
                <div class="pagelist">
                    <a href="javascript:" @click="goPage(1)">首页</a>
                    <a href="javascript:" @click="goPage(pageInfo.prePage)">上一页</a>
                    <!--class="current" 激活状态-->

                    <a href="javascript:" :class="num==pageNumber?'current':''" @click="goPage(num)" v-for="num in pageInfo.navigatepageNums">{{num}}</a>

                    <a href="javascript:" @click="goPage(pageInfo.nextPage)">下一页</a>
                    <a href="javascript:" @click="goPage(pageInfo.pages)">末页</a>
                </div>
            </td>
		</tr>
    </table>
</div>
<script type="text/javascript">
    const app = new Vue({
        el: '#moviesListDiv',
        data: {
            cid:"",  // 选择的分类id
            keyword:"" ,//输入搜索字符
            pageNumber:1,//当前页码
            pageSize : 2, //每页展示的个数
            moviesList:[], //接收后端传递的数据
            moviesIds : [],  //批量删除接受的ids数组
            pageInfo:{} //分页对象
        },
        methods: {
            //查询影视列表的方法
            findList(){
                //发送axios
                axios.get("/moviesController/findList" , {
                    params:{
                        cid:this.cid,
                        keyword:this.keyword,
                        pageNumber: this.pageNumber,
                        pageSize:  this.pageSize
                    }
                }).then(resp=>{
                    console.log(resp.data);
                    //接受后台传递的数据  resp.data == pageInfo
                    this.moviesList= resp.data.list; //数据内容
                    this.pageInfo = resp.data; //分页对象
                })
            },
            //跳转哪一页
            goPage(pageNumber){
                this.pageNumber = pageNumber; //将新的页码赋值给原来的页码
                this.findList(); //重新查询即可
            },

            //根据id删除
            deleteById(moviesId){
                if(confirm("是否删除数据?")){
                    axios.delete("/movies/"+moviesId).then(resp=>{
                        if(resp.data){
                            alert("删除成功")
                            this.findList();//刷新页面数据
                        }else{
                            alert("删除失败")
                        }
                    })
                }

            },
            //批量删除
            deleteByIds(){
                // axios.delete("路径?key=value")  普通的 key=value 传递
                // axios.post("路径" , this.对象 )  普通的json 传递
                // axios.delete("路径/value")      rest风格


                if(confirm("是否删除数据?")){

                    //路径不能跟普通的删除一致 如果一致 服务器区分不了路径
                    //浏览器和服务器进行交互的时候  只有字符串传递
                    //要么将数组 自己转换成 字符串 传递  要么spring mvc中自动封装数组( 普通的 key=value 传递 )
                    axios.delete("/movies/deleteByIds?ids="+this.moviesIds).then(resp=>{
                        if(resp.data){
                            alert("删除成功")
                            this.findList();//刷新页面数据
                        }else{
                            alert("删除失败")
                        }
                    })
                }
            }
        },
        created(){//页面加载函数
            //调用查询的方法
            this.findList();
        }
    })
</script>
<script src="/js/verify.js"></script>
</body>
</html>
<!--
    发送axios请求 校验一下用户是否登录过
    created(){ axios.xxxx  }
-->
